/** 
  Copyright (c) 2008, 2009 Claudio Imbrenda
  This program is released under the terms of the
  GNU GPL version 3 or later.
*/
package interfaccia;

import java.awt.event.*;
import java.awt.*;

import java.io.*;
import javax.sound.sampled.*;
import java.net.URL;
import java.util.prefs.BackingStoreException;
import javax.swing.*;
import java.util.*;
import java.util.prefs.Preferences;
import macchina.*;
import macchina.nastri.*;
import macchina.telescriventi.*;

public class MRMainFrame extends javax.swing.JFrame {
    
    
      private static ResourceBundle bundle_interfaccia = 
          ResourceBundle.getBundle("interfaccia/Bundle_interfaccia");
    
    /**
     * The version number. Approximates 1.
     */
    public static final String VERSION = "0.12345";
    /**
     * Information about the graphical interface.
     */
    public static final String ABOUTSTRING =
            bundle_interfaccia.getString("Interfaccia_grafica_per_l'emulatore_della_Macchina_Ridotta")+"\n"+
            bundle_interfaccia.getString("Versione_")+VERSION+"\n"+
            bundle_interfaccia.getString("Copyright_©_2008,_2009_Claudio_Imbrenda,") +"\n"+
//            bundle_interfaccia.getString("tutti_i_diritti_riservati.") +"\n"+
            bundle_interfaccia.getString("Questo_programma_è_rilasciato_sotto_licenza") +"\n"+
            bundle_interfaccia.getString("GNU_GPL_versione_3_o_successiva.")+"\n\n"+
            "Silk icon set 1.3  [under Creative Commons Attribution 2.5 License]\n"+
            "by Mark James\nhttp://www.famfamfam.com/lab/icons/silk/\n\n"+
            "Teletype sound \"Teletype.flac\" [under Creative Commons Sampling Plus 1.0 License]\n"+
            "by Halleck\nhttp://www.freesound.org\n\n";
    
    private static String defmemimage;
    private static String defmemcolors;
    private static String definstructions;
    private static String deftape;
    private static int deftapetype;
    
    public static final String WINDOWTITLE = "Macchina Ridotta";
    private static boolean nosound=false;
    
        
    /**
     * The instance of MRPanel used to display the historical interface.
     */
    private MRPanel mrp;
    
    /**
     * The instance of MRUberPanel used to display the advanced interface.
     */
    private MRUberPanel ubp;
    
    /**
     * The instance of Macchina to handle.
     */
    private Macchina mrm;
    
    private MRTeletypePanel mtty;

    private MRTeletypePanel classictty;
    
    private MRTapeReaderPanel mtape;

    private static HashMap<String,Clip> suoni = new HashMap<String,Clip>();
    
    /** Creates new form MRMainFrame */
    public MRMainFrame() {
        try{
            UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
//                    Preferences.userNodeForPackage(MRMainFrame.class)
//                        .get("default.lookandfeel",null).toString());
        }catch(NullPointerException ignore){}
        catch(ClassNotFoundException ignore){}
        catch(InstantiationException ignore){}
        catch(UnsupportedLookAndFeelException ignore){}
        catch(IllegalAccessException ignore){}        
        
        
        initComponents();
        
        menuLAF.setVisible(false);
        miSystemDecorations.setVisible(false);
        
        defmemimage = Preferences.userNodeForPackage(MRMainFrame.class)
                .get("default.memory_image", null);
        defmemcolors = Preferences.userNodeForPackage(MRMainFrame.class)
                .get("default.memory_colors", null);
        definstructions = Preferences.userNodeForPackage(MRMainFrame.class)
                .get("default.instruction_set", null);
        deftape = Preferences.userNodeForPackage(MRMainFrame.class)
                .get("default.tape", null);
          deftapetype = Preferences.userNodeForPackage(MRMainFrame.class)
                  .getInt("default.tape.type", -1);

        lastpath=Preferences.userNodeForPackage(MRMainFrame.class)
                .get("default.opendialogs.path",null);

        
        mrm=new Macchina();
        mrp=new MRPanel();
        ubp=new MRUberPanel(mrm);
        mtty=new MRTeletypePanel();
        classictty=new MRTeletypePanel(mrm, true);
        mtape=new MRTapeReaderPanel(mrm);

        mrp.setTapeDisplay(mtape.getHistoricalTapeView());
        
        ActionListener act;
        
        mrp.addActionListener(act=new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            actionmacchina(e);
          }
        });
        ubp.addActionListener(act);
        
        
        mrm.addRU(mtty);
        mrm.addRU(classictty);
        mrm.setAE(mtape);
        
        mrm.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            switch(e.getID()){
            case Macchina.CONFIGURATION_SET_CHANGED:
                updateconfigsmenu();
                break;
            case Macchina.INSTRUCTION_SET_CHANGED:
                break;
            case Macchina.CURRENT_CONFIGURATION_CHANGED:
                String curconf = mrm.getCurrentConfiguration();
                Component[] co = menuConfigs.getMenuComponents();
                for(Component qc:co){
                    if(!(qc instanceof JRadioButtonMenuItem))continue;
                    if(((JRadioButtonMenuItem)qc).getText().equalsIgnoreCase(curconf))
                        ((JRadioButtonMenuItem)qc).setSelected(true);
                    else 
                        ((JRadioButtonMenuItem)qc).setSelected(false);
                }
                setTitle(WINDOWTITLE+" - "+curconf);
                break;
            default:        
                mrp.setRUNNING(mrm.isRunning());
                ubp.setRUNNING(mrm.isRunning());
                miResetClock.setEnabled(!mrm.isRunning());
            }
          }
        });

        mrp.setTelescrivente(classictty);

        updateconfigsmenu();
        setTitle(WINDOWTITLE+" - "+mrm.getCurrentConfiguration());
        jTabbedPane1.addTab(bundle_interfaccia.getString("Storica"), mrp);
        jTabbedPane1.addTab(bundle_interfaccia.getString("Nastro"), mtape);
        jTabbedPane1.addTab(bundle_interfaccia.getString("Telescrivente"), mtty);
        jTabbedPane1.addTab(bundle_interfaccia.getString("Avanzata"), ubp);
        jTabbedPane1.addTab(bundle_interfaccia.getString("Configurazioni"), new MRConfigurationPanel(mrm));
        jTabbedPane1.addTab(bundle_interfaccia.getString("Istruzioni"), new MRInstructionsPanel(mrm));
        
        load_def_mem_image();

        if((defmemcolors!=null)&&!defmemcolors.equals(""))
          try{ 
            setubpcolors(new File(defmemcolors)); 
            miCurDefColors.setText(defmemcolors);
            miDefColors.setSelected(false);
          }catch(FileNotFoundException ignore){}
          catch(IOException ignore){}
        
        if((definstructions!=null)&&!definstructions.equals(""))
          if(mrm.loadInstructionSet(new File(definstructions))){
            miCurDefInstr.setText(definstructions);
            miEmptyDefInstr.setSelected(false);
          }
        
        if((deftape!=null)&&!deftape.equals("")){
          try{
          mtape.load(_mkloader(new File(deftape), deftapetype));
          miCurDefTape.setText(deftape);
          miEmptyDefTape.setSelected(false);
          }catch(FileNotFoundException ignore){}
          catch(NullPointerException ignore){}
        }
        
        UIManager.LookAndFeelInfo lafs[] = UIManager.getInstalledLookAndFeels();
        ButtonGroup g = new ButtonGroup();
        for(UIManager.LookAndFeelInfo i:lafs){
            JRadioButtonMenuItem cur;
            final String laf_class = i.getClassName();
            menuLAF.add(cur=new JRadioButtonMenuItem(i.getName(),
                    UIManager.getLookAndFeel().getName().equals(i.getName())));
            cur.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    try{
                        UIManager.setLookAndFeel(laf_class);
                        Preferences.userNodeForPackage(MRMainFrame.class)
                                .put("default.lookandfeel",laf_class);
                        SwingUtilities.updateComponentTreeUI(MRMainFrame.this);
                    }catch(ClassNotFoundException ignore){}
                    catch(InstantiationException ignore){}
                    catch(IllegalAccessException ignore){}
                    catch(UnsupportedLookAndFeelException ignore){}
                    
                }
            });
            g.add(cur);
        }
        
        
        miSystemDecorations.setSelected(!JFrame.isDefaultLookAndFeelDecorated());
        setSize(800, 570);
        Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
        setLocation((d.width-800)/2, (d.height-570)/2);

        
        miSoundFX.setSelected(Preferences.userNodeForPackage(MRMainFrame.class)
            .getBoolean("sound.enabled", false));
        if(nosound){
            miSoundFX.setSelected(false);
            miSoundFX.setEnabled(false);
        }
        classictty.setSoundEnabled(miSoundFX.isSelected());
        
    }

    private void load_def_mem_image() {
        if((defmemimage!=null)&&!defmemimage.equals(""))
        try{
            mrm.loadMemDump(new File(defmemimage), 0);
            miCurDefMemory.setText(defmemimage);
            miEmptyDefMemory.setSelected(false);
        }catch(FileNotFoundException ignore){}
        catch(IOException ignore){}
        else mrm.loadMEM(new int[1024]);
    }
    
    /**
     * Updates the configurations menu with the available configurations.
     */
    private void updateconfigsmenu(){
        SwingUtilities.invokeLater(new Runnable() { public void run() {
                    menuConfigs.removeAll();
                    JRadioButtonMenuItem sel=null;
                    String curconf = mrm.getCurrentConfiguration();
                    for (String s:mrm.getConfigurations()){
                        final String nome = s;
                        final JRadioButtonMenuItem jm;
                        menuConfigs.add(jm=new JRadioButtonMenuItem(nome));
                        jm.addActionListener(new ActionListener() {
                            public void actionPerformed(ActionEvent e) {
                              mrm.setConfiguration(nome);
                        }});
                        if(s.equalsIgnoreCase(curconf))sel=jm;
                        jm.setSelected(false);
                    }
                    sel.setSelected(true);
                } });
    }
    
    
    private AdattatoreEntrata _mkloader(File f, int t)
                                                throws FileNotFoundException{
        switch(t){
            case 0:
                return new NastroFileNastro(f);
            case 1:
                return new ASCIIFileNastro(f);
            case 2:
                return new BinaryFileNastro(f);
            case 3:
                return new NumberFileNastro(f);
            default:
                return null;
        }
    }
    
     private RegistroUscita _mkwriter(File f, int t)
                                    throws FileNotFoundException,IOException{
        switch(t){
            case 0:
                return new ASCIIFileTelescrivente(f);
            case 1:
                return new BinaryFileTelescrivente(f);
            case 2:
                return new NumberFileTelescrivente(f);
            case 3:
                return new NastroFileTelescrivente(f);
            default:
                return null;
        }
    }   
    /**
     * Handles the events from the Macchina.
     * @param e the event to be handled.
     */
    private void actionmacchina(ActionEvent e){
      MRPanelInterface pp;
      MRPanelInterface io;
      if(e.getSource()==mrp){
        io=mrp;
        pp=ubp;
      }else{
        pp=mrp;
        io=ubp;
      }
      
      switch(e.getID()){
        case MRPanel.FLAG_TM:
          mrm.setTM(io.getTM());
          pp.setTM(io.getTM());
          break;
        case MRPanel.FLAG_TI:
          mrm.setTI(io.getTI());
          pp.setTI(io.getTI());
          break;
        case MRPanel.FLAG_MODE:
          mrm.setMode(io.getMode());
          pp.setMode(io.getMode());
          break;
        case MRPanel.FLAG_AC:
          mrm.setAC(io.getAC());
          pp.setAC(io.getAC());
          break;
        case MRPanel.FLAG_EXT:
          mrm.setExternal(io.getExternal());
          pp.setExternal(io.getExternal());
          break;
        case MRPanel.FLAG_START:
          mrm.start();
          mrp.setVI(mrm.getVI());
          ubp.setVI(mrm.getVI());
          mrp.setRUNNING(mrm.isRunning());
          ubp.setRUNNING(mrm.isRunning());
          ubp.updateMEM();
          mtape.updateStatus();
          break;
        default:
      }
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
  private void initComponents() {

    speedGroup = new javax.swing.ButtonGroup();
    refreshGroup = new javax.swing.ButtonGroup();
    jTabbedPane1 = new javax.swing.JTabbedPane();
    jMenuBar1 = new javax.swing.JMenuBar();
    jMenu1 = new javax.swing.JMenu();
    miLoadMemory = new javax.swing.JMenuItem();
    mnuResetToLastImage = new javax.swing.JMenuItem();
    miDumpMemory = new javax.swing.JMenuItem();
    jMenu5 = new javax.swing.JMenu();
    miEmptyDefMemory = new javax.swing.JCheckBoxMenuItem();
    jSeparator5 = new javax.swing.JSeparator();
    miNewDefMemory = new javax.swing.JMenuItem();
    jMenuItem12 = new javax.swing.JMenuItem();
    miCurDefMemory = new javax.swing.JMenuItem();
    mnuResetToDefaultImage = new javax.swing.JMenuItem();
    jSeparator1 = new javax.swing.JSeparator();
    miLoadInstr = new javax.swing.JMenuItem();
    miSaveInstr = new javax.swing.JMenuItem();
    jMenu7 = new javax.swing.JMenu();
    miEmptyDefInstr = new javax.swing.JCheckBoxMenuItem();
    jSeparator7 = new javax.swing.JSeparator();
    miNewDefInstr = new javax.swing.JMenuItem();
    jMenuItem17 = new javax.swing.JMenuItem();
    miCurDefInstr = new javax.swing.JMenuItem();
    jSeparator2 = new javax.swing.JSeparator();
    miQuit = new javax.swing.JMenuItem();
    jMenu9 = new javax.swing.JMenu();
    miLoadTape = new javax.swing.JMenuItem();
    miSaveTape = new javax.swing.JMenuItem();
    jMenu13 = new javax.swing.JMenu();
    miEmptyDefTape = new javax.swing.JCheckBoxMenuItem();
    jSeparator8 = new javax.swing.JSeparator();
    miNewDefTape = new javax.swing.JMenuItem();
    jMenuItem26 = new javax.swing.JMenuItem();
    miCurDefTape = new javax.swing.JMenuItem();
    jSeparator4 = new javax.swing.JSeparator();
    miSaveTeletype = new javax.swing.JMenuItem();
    jMenu2 = new javax.swing.JMenu();
    jMenu3 = new javax.swing.JMenu();
    miSpeedBest = new javax.swing.JRadioButtonMenuItem();
    miSpeedHistorical = new javax.swing.JRadioButtonMenuItem();
    miSpeedSlow = new javax.swing.JRadioButtonMenuItem();
    miSpeedVerySlow = new javax.swing.JRadioButtonMenuItem();
    menuConfigs = new javax.swing.JMenu();
    jMenu8 = new javax.swing.JMenu();
    miLoadColors = new javax.swing.JMenuItem();
    miSaveColors = new javax.swing.JMenuItem();
    jMenu6 = new javax.swing.JMenu();
    miDefColors = new javax.swing.JCheckBoxMenuItem();
    jSeparator6 = new javax.swing.JSeparator();
    miNewDefColors = new javax.swing.JMenuItem();
    jMenuItem14 = new javax.swing.JMenuItem();
    miCurDefColors = new javax.swing.JMenuItem();
    jSeparator3 = new javax.swing.JSeparator();
    miResetClock = new javax.swing.JMenuItem();
    jSeparator10 = new javax.swing.JSeparator();
    jMenu4 = new javax.swing.JMenu();
    miRefresh1s = new javax.swing.JRadioButtonMenuItem();
    miRefresh500ms = new javax.swing.JRadioButtonMenuItem();
    miRefresh200ms = new javax.swing.JRadioButtonMenuItem();
    miRefresh100ms = new javax.swing.JRadioButtonMenuItem();
    miRefresh50ms = new javax.swing.JRadioButtonMenuItem();
    miRefresh20ms = new javax.swing.JRadioButtonMenuItem();
    jMenu10 = new javax.swing.JMenu();
    menuLAF = new javax.swing.JMenu();
    miSystemDecorations = new javax.swing.JCheckBoxMenuItem();
    jSeparator13 = new javax.swing.JSeparator();
    miSoundFX = new javax.swing.JCheckBoxMenuItem();
    jSeparator12 = new javax.swing.JSeparator();
    jMenu11 = new javax.swing.JMenu();
    miDefaultLanguage = new javax.swing.JMenuItem();
    jSeparator11 = new javax.swing.JSeparator();
    miItalian = new javax.swing.JMenuItem();
    miEnglish = new javax.swing.JMenuItem();
    miEsperanto = new javax.swing.JMenuItem();
    jSeparator9 = new javax.swing.JSeparator();
    miInformations = new javax.swing.JMenuItem();

    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
    setTitle(bundle_interfaccia.getString("Macchina_Ridotta")); // NOI18N
    setLocationByPlatform(true);
    setMinimumSize(new java.awt.Dimension(570, 400));
    getContentPane().add(jTabbedPane1, java.awt.BorderLayout.CENTER);

    jMenu1.setText(bundle_interfaccia.getString("File")); // NOI18N

    miLoadMemory.setIcon(new javax.swing.ImageIcon(getClass().getResource("/interfaccia/folder_go.png"))); // NOI18N
    miLoadMemory.setText(bundle_interfaccia.getString("Load_memory_image...")); // NOI18N
    miLoadMemory.setToolTipText(bundle_interfaccia.getString("Loads_a_memory_dump")); // NOI18N
    miLoadMemory.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        miLoadMemoryActionPerformed(evt);
      }
    });
    jMenu1.add(miLoadMemory);

    mnuResetToLastImage.setIcon(new javax.swing.ImageIcon(getClass().getResource("/interfaccia/reset.png"))); // NOI18N
    java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("interfaccia/Bundle_interfaccia"); // NOI18N
    mnuResetToLastImage.setText(bundle.getString("Reset_to_last_image")); // NOI18N
    mnuResetToLastImage.setToolTipText(bundle.getString("Resets_to_default_image")); // NOI18N
    mnuResetToLastImage.setEnabled(false);
    mnuResetToLastImage.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        mnuResetToLastImageActionPerformed(evt);
      }
    });
    jMenu1.add(mnuResetToLastImage);

    miDumpMemory.setIcon(new javax.swing.ImageIcon(getClass().getResource("/interfaccia/disk.png"))); // NOI18N
    miDumpMemory.setText(bundle_interfaccia.getString("Dump_memory_image...")); // NOI18N
    miDumpMemory.setToolTipText(bundle_interfaccia.getString("Dumps_the_memory_to_file")); // NOI18N
    miDumpMemory.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        miDumpMemoryActionPerformed(evt);
      }
    });
    jMenu1.add(miDumpMemory);

    jMenu5.setText(bundle_interfaccia.getString("Default_memory_image")); // NOI18N

    miEmptyDefMemory.setSelected(true);
    miEmptyDefMemory.setText(bundle_interfaccia.getString("Empty_image")); // NOI18N
    miEmptyDefMemory.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        miEmptyDefMemoryActionPerformed(evt);
      }
    });
    jMenu5.add(miEmptyDefMemory);
    jMenu5.add(jSeparator5);

    miNewDefMemory.setText(bundle_interfaccia.getString("Choose_new...")); // NOI18N
    miNewDefMemory.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        miNewDefMemoryActionPerformed(evt);
      }
    });
    jMenu5.add(miNewDefMemory);

    jMenuItem12.setText(bundle_interfaccia.getString("Current_default:")); // NOI18N
    jMenuItem12.setEnabled(false);
    jMenu5.add(jMenuItem12);

    miCurDefMemory.setText(null);
    miCurDefMemory.setEnabled(false);
    jMenu5.add(miCurDefMemory);

    jMenu1.add(jMenu5);

    mnuResetToDefaultImage.setIcon(new javax.swing.ImageIcon(getClass().getResource("/interfaccia/reset.png"))); // NOI18N
    mnuResetToDefaultImage.setText(bundle.getString("Reset_to_default_image")); // NOI18N
    mnuResetToDefaultImage.setToolTipText(bundle.getString("Resets_to_default_image")); // NOI18N
    mnuResetToDefaultImage.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        mnuResetToDefaultImageActionPerformed(evt);
      }
    });
    jMenu1.add(mnuResetToDefaultImage);
    jMenu1.add(jSeparator1);

    miLoadInstr.setIcon(new javax.swing.ImageIcon(getClass().getResource("/interfaccia/folder_go.png"))); // NOI18N
    miLoadInstr.setText(bundle_interfaccia.getString("Load_instruction_set...")); // NOI18N
    miLoadInstr.setToolTipText(bundle_interfaccia.getString("Loads_an_instruction_and_configuration_set.")); // NOI18N
    miLoadInstr.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        miLoadInstrActionPerformed(evt);
      }
    });
    jMenu1.add(miLoadInstr);

    miSaveInstr.setIcon(new javax.swing.ImageIcon(getClass().getResource("/interfaccia/disk_multiple.png"))); // NOI18N
    miSaveInstr.setText(bundle_interfaccia.getString("Save_instrucion_set...")); // NOI18N
    miSaveInstr.setToolTipText(bundle_interfaccia.getString("Saves_the_current_instruction_and_configuration_set.")); // NOI18N
    miSaveInstr.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        miSaveInstrActionPerformed(evt);
      }
    });
    jMenu1.add(miSaveInstr);

    jMenu7.setText(bundle_interfaccia.getString("Default_instruction_set")); // NOI18N

    miEmptyDefInstr.setSelected(true);
    miEmptyDefInstr.setText(bundle_interfaccia.getString("Macchina_Ridotta_1955")); // NOI18N
    miEmptyDefInstr.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        miEmptyDefInstrActionPerformed(evt);
      }
    });
    jMenu7.add(miEmptyDefInstr);
    jMenu7.add(jSeparator7);

    miNewDefInstr.setText(bundle_interfaccia.getString("Choose_new...")); // NOI18N
    miNewDefInstr.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        miNewDefInstrActionPerformed(evt);
      }
    });
    jMenu7.add(miNewDefInstr);

    jMenuItem17.setText(bundle_interfaccia.getString("Current_default:")); // NOI18N
    jMenuItem17.setEnabled(false);
    jMenu7.add(jMenuItem17);

    miCurDefInstr.setText(null);
    miCurDefInstr.setEnabled(false);
    jMenu7.add(miCurDefInstr);

    jMenu1.add(jMenu7);
    jMenu1.add(jSeparator2);

    miQuit.setIcon(new javax.swing.ImageIcon(getClass().getResource("/interfaccia/cross.png"))); // NOI18N
    miQuit.setText(bundle_interfaccia.getString("Quit")); // NOI18N
    miQuit.setToolTipText(bundle_interfaccia.getString("Terminates_the_program")); // NOI18N
    miQuit.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        miQuitActionPerformed(evt);
      }
    });
    jMenu1.add(miQuit);

    jMenuBar1.add(jMenu1);

    jMenu9.setText(bundle_interfaccia.getString("I/O")); // NOI18N

    miLoadTape.setIcon(new javax.swing.ImageIcon(getClass().getResource("/interfaccia/folder_go.png"))); // NOI18N
    miLoadTape.setText(bundle_interfaccia.getString("Load_tape...")); // NOI18N
    miLoadTape.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        miLoadTapeActionPerformed(evt);
      }
    });
    jMenu9.add(miLoadTape);

    miSaveTape.setIcon(new javax.swing.ImageIcon(getClass().getResource("/interfaccia/disk.png"))); // NOI18N
    miSaveTape.setText(bundle_interfaccia.getString("Save_current_tape...")); // NOI18N
    miSaveTape.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        miSaveTapeActionPerformed(evt);
      }
    });
    jMenu9.add(miSaveTape);

    jMenu13.setText(bundle_interfaccia.getString("Default_tape")); // NOI18N

    miEmptyDefTape.setSelected(true);
    miEmptyDefTape.setText(bundle_interfaccia.getString("Empty_tape")); // NOI18N
    miEmptyDefTape.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        miEmptyDefTapeActionPerformed(evt);
      }
    });
    jMenu13.add(miEmptyDefTape);
    jMenu13.add(jSeparator8);

    miNewDefTape.setText(bundle_interfaccia.getString("Choose_new...")); // NOI18N
    miNewDefTape.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        miNewDefTapeActionPerformed(evt);
      }
    });
    jMenu13.add(miNewDefTape);

    jMenuItem26.setText(bundle_interfaccia.getString("Current_default:")); // NOI18N
    jMenuItem26.setEnabled(false);
    jMenu13.add(jMenuItem26);

    miCurDefTape.setText(" ");
    miCurDefTape.setEnabled(false);
    jMenu13.add(miCurDefTape);

    jMenu9.add(jMenu13);
    jMenu9.add(jSeparator4);

    miSaveTeletype.setIcon(new javax.swing.ImageIcon(getClass().getResource("/interfaccia/disk.png"))); // NOI18N
    miSaveTeletype.setText(bundle_interfaccia.getString("Save_teletype_output...")); // NOI18N
    miSaveTeletype.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        miSaveTeletypeActionPerformed(evt);
      }
    });
    jMenu9.add(miSaveTeletype);

    jMenuBar1.add(jMenu9);

    jMenu2.setText(bundle_interfaccia.getString("Macchina")); // NOI18N

    jMenu3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/interfaccia/lightning.png"))); // NOI18N
    jMenu3.setText(bundle_interfaccia.getString("Set_Speed")); // NOI18N

    speedGroup.add(miSpeedBest);
    miSpeedBest.setSelected(true);
    miSpeedBest.setText(bundle_interfaccia.getString("Best")); // NOI18N
    miSpeedBest.setToolTipText(bundle_interfaccia.getString("Best_speed")); // NOI18N
    miSpeedBest.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        miSpeedBestActionPerformed(evt);
      }
    });
    jMenu3.add(miSpeedBest);

    speedGroup.add(miSpeedHistorical);
    miSpeedHistorical.setText(bundle_interfaccia.getString("Historical")); // NOI18N
    miSpeedHistorical.setToolTipText(bundle_interfaccia.getString("Historically_accurate_speed")); // NOI18N
    miSpeedHistorical.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        miSpeedHistoricalActionPerformed(evt);
      }
    });
    jMenu3.add(miSpeedHistorical);

    speedGroup.add(miSpeedSlow);
    miSpeedSlow.setText(bundle_interfaccia.getString("Slow")); // NOI18N
    miSpeedSlow.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        miSpeedSlowActionPerformed(evt);
      }
    });
    jMenu3.add(miSpeedSlow);

    speedGroup.add(miSpeedVerySlow);
    miSpeedVerySlow.setText(bundle_interfaccia.getString("Very_Slow")); // NOI18N
    miSpeedVerySlow.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        miSpeedVerySlowActionPerformed(evt);
      }
    });
    jMenu3.add(miSpeedVerySlow);

    jMenu2.add(jMenu3);

    menuConfigs.setIcon(new javax.swing.ImageIcon(getClass().getResource("/interfaccia/wrench_orange.png"))); // NOI18N
    menuConfigs.setText(bundle_interfaccia.getString("Set_Configuration")); // NOI18N
    jMenu2.add(menuConfigs);

    jMenuBar1.add(jMenu2);

    jMenu8.setText(bundle_interfaccia.getString("Avanzata")); // NOI18N

    miLoadColors.setIcon(new javax.swing.ImageIcon(getClass().getResource("/interfaccia/folder_go.png"))); // NOI18N
    miLoadColors.setText(bundle_interfaccia.getString("Load_memory_configuration...")); // NOI18N
    miLoadColors.setToolTipText(bundle_interfaccia.getString("Loads_a_saved_memory_configuration")); // NOI18N
    miLoadColors.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        miLoadColorsActionPerformed(evt);
      }
    });
    jMenu8.add(miLoadColors);

    miSaveColors.setIcon(new javax.swing.ImageIcon(getClass().getResource("/interfaccia/disk.png"))); // NOI18N
    miSaveColors.setText(bundle_interfaccia.getString("Save_memory_configuration...")); // NOI18N
    miSaveColors.setToolTipText(bundle_interfaccia.getString("Saves_the_current_memory_configuration")); // NOI18N
    miSaveColors.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        miSaveColorsActionPerformed(evt);
      }
    });
    jMenu8.add(miSaveColors);

    jMenu6.setText(bundle_interfaccia.getString("Default_memory_configuration")); // NOI18N

    miDefColors.setSelected(true);
    miDefColors.setText(bundle_interfaccia.getString("Default_configuration")); // NOI18N
    miDefColors.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        miDefColorsActionPerformed(evt);
      }
    });
    jMenu6.add(miDefColors);
    jMenu6.add(jSeparator6);

    miNewDefColors.setText(bundle_interfaccia.getString("Choose_new...")); // NOI18N
    miNewDefColors.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        miNewDefColorsActionPerformed(evt);
      }
    });
    jMenu6.add(miNewDefColors);

    jMenuItem14.setText(bundle_interfaccia.getString("Current_default:")); // NOI18N
    jMenuItem14.setEnabled(false);
    jMenu6.add(jMenuItem14);

    miCurDefColors.setText(null);
    miCurDefColors.setEnabled(false);
    jMenu6.add(miCurDefColors);

    jMenu8.add(jMenu6);
    jMenu8.add(jSeparator3);

    miResetClock.setIcon(new javax.swing.ImageIcon(getClass().getResource("/interfaccia/reset.png"))); // NOI18N
    miResetClock.setText(bundle_interfaccia.getString("Reset_Clock_Counter")); // NOI18N
    miResetClock.setToolTipText(bundle_interfaccia.getString("Resets_the_clock_cycle_counter")); // NOI18N
    miResetClock.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        miResetClockActionPerformed(evt);
      }
    });
    jMenu8.add(miResetClock);
    jMenu8.add(jSeparator10);

    jMenu4.setText(bundle_interfaccia.getString("Refresh")); // NOI18N

    refreshGroup.add(miRefresh1s);
    miRefresh1s.setSelected(true);
    miRefresh1s.setText("1s");
    miRefresh1s.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jMenuitem19ActionPerformed(evt);
      }
    });
    jMenu4.add(miRefresh1s);

    refreshGroup.add(miRefresh500ms);
    miRefresh500ms.setText("500ms");
    miRefresh500ms.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jMenuitem19ActionPerformed(evt);
      }
    });
    jMenu4.add(miRefresh500ms);

    refreshGroup.add(miRefresh200ms);
    miRefresh200ms.setText("200ms");
    miRefresh200ms.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jMenuitem19ActionPerformed(evt);
      }
    });
    jMenu4.add(miRefresh200ms);

    refreshGroup.add(miRefresh100ms);
    miRefresh100ms.setText("100ms");
    miRefresh100ms.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jMenuitem19ActionPerformed(evt);
      }
    });
    jMenu4.add(miRefresh100ms);

    refreshGroup.add(miRefresh50ms);
    miRefresh50ms.setText("50 ms");
    miRefresh50ms.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jMenuitem19ActionPerformed(evt);
      }
    });
    jMenu4.add(miRefresh50ms);

    refreshGroup.add(miRefresh20ms);
    miRefresh20ms.setText("20 ms");
    miRefresh20ms.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jMenuitem19ActionPerformed(evt);
      }
    });
    jMenu4.add(miRefresh20ms);

    jMenu8.add(jMenu4);

    jMenuBar1.add(jMenu8);

    jMenu10.setText(bundle_interfaccia.getString("Interfaccia")); // NOI18N

    menuLAF.setIcon(new javax.swing.ImageIcon(getClass().getResource("/interfaccia/application_view_gallery.png"))); // NOI18N
    menuLAF.setText(bundle_interfaccia.getString("Imposta_stile_interfaccia")); // NOI18N
    menuLAF.setEnabled(false);
    jMenu10.add(menuLAF);

    miSystemDecorations.setSelected(true);
    miSystemDecorations.setText(bundle_interfaccia.getString("Usa_decorazioni_di_sistema")); // NOI18N
    miSystemDecorations.setToolTipText(bundle_interfaccia.getString("Usa_le_decorazioni_di_sistema_per_le_finestre._Necessita_il_riavvio_del_programma_per_avere_effetto.")); // NOI18N
    miSystemDecorations.setEnabled(false);
    miSystemDecorations.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        miSystemDecorationsActionPerformed(evt);
      }
    });
    jMenu10.add(miSystemDecorations);
    jMenu10.add(jSeparator13);

    miSoundFX.setText(bundle.getString("Effetti_sonori")); // NOI18N
    miSoundFX.setIcon(new javax.swing.ImageIcon(getClass().getResource("/interfaccia/sound.png"))); // NOI18N
    miSoundFX.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        miSoundFXActionPerformed(evt);
      }
    });
    jMenu10.add(miSoundFX);
    jMenu10.add(jSeparator12);

    jMenu11.setIcon(new javax.swing.ImageIcon(getClass().getResource("/interfaccia/flag_orange.png"))); // NOI18N
    jMenu11.setText(bundle_interfaccia.getString("Lingua")); // NOI18N

    miDefaultLanguage.setText(bundle_interfaccia.getString("Default")); // NOI18N
    miDefaultLanguage.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        miDefaultLanguageActionPerformed(evt);
      }
    });
    jMenu11.add(miDefaultLanguage);
    jMenu11.add(jSeparator11);

    miItalian.setIcon(new javax.swing.ImageIcon(getClass().getResource("/interfaccia/it.png"))); // NOI18N
    miItalian.setText("Italiano");
    miItalian.setToolTipText(bundle_interfaccia.getString("Le_impostazioni_linguistiche_necessitano_il_riavvio_del_programma")); // NOI18N
    miItalian.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        miItalianActionPerformed(evt);
      }
    });
    jMenu11.add(miItalian);

    miEnglish.setIcon(new javax.swing.ImageIcon(getClass().getResource("/interfaccia/gb.png"))); // NOI18N
    miEnglish.setText("English");
    miEnglish.setToolTipText(bundle_interfaccia.getString("Le_impostazioni_linguistiche_necessitano_il_riavvio_del_programma")); // NOI18N
    miEnglish.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        miEnglishActionPerformed(evt);
      }
    });
    jMenu11.add(miEnglish);

    miEsperanto.setIcon(new javax.swing.ImageIcon(getClass().getResource("/interfaccia/eo.png"))); // NOI18N
    miEsperanto.setText("Esperanto");
    miEsperanto.setToolTipText(bundle_interfaccia.getString("Le_impostazioni_linguistiche_necessitano_il_riavvio_del_programma")); // NOI18N
    miEsperanto.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        miEsperantoActionPerformed(evt);
      }
    });
    jMenu11.add(miEsperanto);

    jMenu10.add(jMenu11);
    jMenu10.add(jSeparator9);

    miInformations.setIcon(new javax.swing.ImageIcon(getClass().getResource("/interfaccia/information.png"))); // NOI18N
    miInformations.setText(bundle_interfaccia.getString("Informazioni...")); // NOI18N
    miInformations.setToolTipText(bundle_interfaccia.getString("Copyright_and_version_information_about_the_emulator_and_the_graphical_interface")); // NOI18N
    miInformations.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        miInformationsActionPerformed(evt);
      }
    });
    jMenu10.add(miInformations);

    jMenuBar1.add(jMenu10);

    setJMenuBar(jMenuBar1);

    pack();
  }// </editor-fold>//GEN-END:initComponents

  private void miQuitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miQuitActionPerformed
       System.exit(0);
}//GEN-LAST:event_miQuitActionPerformed

  private void miDumpMemoryActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miDumpMemoryActionPerformed
    JFileChooser jf = new JFileChooser();
    jf.setDialogTitle(bundle_interfaccia.getString("Salva_Dump_della_memoria"));
    jf.setDialogType(JFileChooser.SAVE_DIALOG);
    jf.setMultiSelectionEnabled(false);
    if(jf.showSaveDialog(null)==JFileChooser.CANCEL_OPTION)return;
    try{
      if(jf.getSelectedFile()!=null)mrm.dumpMEM(jf.getSelectedFile());
      return;
    }catch(FileNotFoundException e){
    }catch(IOException e){}
    
    JOptionPane.showMessageDialog(null, bundle_interfaccia.getString("Errore_nel_salvataggio!"), bundle_interfaccia.getString("Errore!"),
                  JOptionPane.ERROR_MESSAGE);
}//GEN-LAST:event_miDumpMemoryActionPerformed

  
  /**
   * The last path used to save or load memory dumps.
   */
  private String lastpath;
  private String lastloaded;
  private int last_base;
  private void miLoadMemoryActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miLoadMemoryActionPerformed
    JFileChooser jf = new JFileChooser();
    if(lastpath!=null)jf.setSelectedFile(new File(lastpath));
    int i=0;
    jf.setDialogTitle(bundle_interfaccia.getString("Carica_Dump_della_memoria"));
    jf.setDialogType(JFileChooser.OPEN_DIALOG);
    jf.setMultiSelectionEnabled(false);
    if(jf.showOpenDialog(null)==JFileChooser.CANCEL_OPTION)return;
    if(jf.getSelectedFile()==null)return;
    
    String res=JOptionPane.showInputDialog(
            bundle_interfaccia.getString("Indirizzo_base_per_il_caricamento_del_dump:"),
                  0/*ubp.getSelected()<0?"":""+ubp.getSelected()*/);
    if(res==null)return;
    if(res.equals(""))res="0";
    try{
      i=(new Integer(res)).intValue();
      last_base=i;
      if(jf.getSelectedFile()!=null){
        mrm.loadMemDump(jf.getSelectedFile(),i);
        ubp.updateMEM();
        lastloaded=lastpath=jf.getSelectedFile().getAbsolutePath();
        mnuResetToLastImage.setEnabled(true);
        Preferences.userNodeForPackage(MRMainFrame.class).put("default.opendialogs.path", lastpath);
      }
      return;
    }catch(FileNotFoundException e){
    }catch(IOException e){
    }catch(NumberFormatException e){}
    
    JOptionPane.showMessageDialog(null, bundle_interfaccia.getString("Errore_nel_caricamento!"), bundle_interfaccia.getString("Errore!"),
                  JOptionPane.ERROR_MESSAGE);
}//GEN-LAST:event_miLoadMemoryActionPerformed

  private void miInformationsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miInformationsActionPerformed
    JOptionPane.showMessageDialog(null, ABOUTSTRING+"\n"+Macchina.ABOUTSTRING,
            bundle_interfaccia.getString("Informazioni"), JOptionPane.INFORMATION_MESSAGE);
}//GEN-LAST:event_miInformationsActionPerformed

 
  private void setubpcolors(File f)throws FileNotFoundException,IOException{
    if(f!=null){
        int[] neucol = new int[1024];
        int cx;
        for(cx=0;cx<1024;cx++)neucol[cx]=-1;
        BufferedReader bre = new BufferedReader(
                  new FileReader(f));
        String inp="";
        cx=0;
        
        while(inp!=null){
          inp=bre.readLine();
          if(inp==null)break;
          inp=inp.trim();
          neucol[cx++]=Integer.parseInt(inp);
        }
        bre.close();
        ubp.setColors(neucol);
        lastpath=f.getAbsolutePath();
        Preferences.userNodeForPackage(MRMainFrame.class).put("default.opendialogs.path", lastpath);
      }
  }
  
  private void miLoadColorsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miLoadColorsActionPerformed
    JFileChooser jf = new JFileChooser();
    if(lastpath!=null)jf.setSelectedFile(new File(lastpath));
    int i=0;
    jf.setDialogTitle(bundle_interfaccia.getString("Carica_Configurazione_della_memoria"));
    jf.setDialogType(JFileChooser.OPEN_DIALOG);
    jf.setMultiSelectionEnabled(false);
    if(jf.showOpenDialog(null)==JFileChooser.CANCEL_OPTION)return;
    if(jf.getSelectedFile()==null)return;
   
    try{
      setubpcolors(jf.getSelectedFile());
      lastpath=jf.getSelectedFile().getAbsolutePath();
      Preferences.userNodeForPackage(MRMainFrame.class).put("default.opendialogs.path", lastpath);
      return;
    }catch(FileNotFoundException e){
    }catch(IOException e){
    }catch(NumberFormatException e){}
    
    JOptionPane.showMessageDialog(null, bundle_interfaccia.getString("Errore_nel_caricamento!"), bundle_interfaccia.getString("Errore!"),
                  JOptionPane.ERROR_MESSAGE);
}//GEN-LAST:event_miLoadColorsActionPerformed

  private void miSaveColorsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miSaveColorsActionPerformed

    JFileChooser jf = new JFileChooser();
    if(lastpath!=null)jf.setSelectedFile(new File(lastpath));
    jf.setDialogTitle(bundle_interfaccia.getString("Salva_Configurazione_della_memoria"));
    jf.setDialogType(JFileChooser.SAVE_DIALOG);
    jf.setMultiSelectionEnabled(false);
    if(jf.showSaveDialog(null)==JFileChooser.CANCEL_OPTION)return;
    try{
      if(jf.getSelectedFile()!=null){
          PrintWriter fw = new PrintWriter(jf.getSelectedFile());
          int[] colori = ubp.getColors();
          for(int c:colori)fw.println(c);
          fw.close();
          lastpath=jf.getSelectedFile().getAbsolutePath();
          Preferences.userNodeForPackage(MRMainFrame.class).put("default.opendialogs.path", lastpath);
      }
      return;
    }catch(FileNotFoundException e){
    }catch(IOException e){}
    
    JOptionPane.showMessageDialog(null, bundle_interfaccia.getString("Errore_nel_salvataggio!"), bundle_interfaccia.getString("Errore!"),
                  JOptionPane.ERROR_MESSAGE);
}//GEN-LAST:event_miSaveColorsActionPerformed

  private void miResetClockActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miResetClockActionPerformed
    mrm.resetClockCount();
    ubp.updateMEM();
}//GEN-LAST:event_miResetClockActionPerformed

  private void miSpeedBestActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miSpeedBestActionPerformed
    mrm.setSpeed(Macchina.SPEED_BEST);
}//GEN-LAST:event_miSpeedBestActionPerformed

  private void miSpeedHistoricalActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miSpeedHistoricalActionPerformed
    mrm.setSpeed(Macchina.SPEED_HISTORIC);
}//GEN-LAST:event_miSpeedHistoricalActionPerformed

  private void miLoadInstrActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miLoadInstrActionPerformed
    JFileChooser jf = new JFileChooser();
    if(lastpath!=null)jf.setSelectedFile(new File(lastpath));
    jf.setDialogTitle(bundle_interfaccia.getString("Carica_set_di_istruzioni"));
    jf.setDialogType(JFileChooser.OPEN_DIALOG);
    jf.setMultiSelectionEnabled(false);
    if(jf.showOpenDialog(null)==JFileChooser.CANCEL_OPTION)return;
    if(jf.getSelectedFile()!=null){
        lastpath=jf.getSelectedFile().getAbsolutePath();
        if(!mrm.loadInstructionSet(jf.getSelectedFile()))
            JOptionPane.showMessageDialog(null, bundle_interfaccia.getString("Errore_nel_caricamento!"),
                    bundle_interfaccia.getString("Errore!"), JOptionPane.ERROR_MESSAGE);
        Preferences.userNodeForPackage(MRMainFrame.class).put("default.opendialogs.path", lastpath);
    }
}//GEN-LAST:event_miLoadInstrActionPerformed

  private void miSaveInstrActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miSaveInstrActionPerformed
    JFileChooser jf = new JFileChooser();    
    if(lastpath!=null)jf.setSelectedFile(new File(lastpath));
    jf.setDialogTitle(bundle_interfaccia.getString("Salva_set_di_istruzioni"));
    jf.setDialogType(JFileChooser.SAVE_DIALOG);
    jf.setMultiSelectionEnabled(false);
    if(jf.showSaveDialog(null)==JFileChooser.CANCEL_OPTION)return;
    if(jf.getSelectedFile()!=null){
        lastpath=jf.getSelectedFile().getAbsolutePath();
        if(!mrm.saveInstructionSet(jf.getSelectedFile()))
            JOptionPane.showMessageDialog(null, bundle_interfaccia.getString("Errore_nel_salvataggio!"),
                    bundle_interfaccia.getString("Errore!"), JOptionPane.ERROR_MESSAGE);
        Preferences.userNodeForPackage(MRMainFrame.class).put("default.opendialogs.path", lastpath);
    }
}//GEN-LAST:event_miSaveInstrActionPerformed

  private void miSpeedSlowActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miSpeedSlowActionPerformed
    mrm.setSpeed(Macchina.SPEED_SLOW);
}//GEN-LAST:event_miSpeedSlowActionPerformed

  private void miSpeedVerySlowActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miSpeedVerySlowActionPerformed
    mrm.setSpeed(Macchina.SPEED_VERY_SLOW);
}//GEN-LAST:event_miSpeedVerySlowActionPerformed

  private void miEmptyDefMemoryActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miEmptyDefMemoryActionPerformed
    miEmptyDefMemory.setSelected(true);
    Preferences.userNodeForPackage(MRMainFrame.class)
            .remove("default.memory_image");
    miCurDefMemory.setText("");
    defmemimage=null;
}//GEN-LAST:event_miEmptyDefMemoryActionPerformed

  private void miDefColorsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miDefColorsActionPerformed
    miDefColors.setSelected(true);
    Preferences.userNodeForPackage(MRMainFrame.class)
            .remove("default.memory_colors");
    miCurDefColors.setText("");
    defmemcolors=null;
}//GEN-LAST:event_miDefColorsActionPerformed

  private void miEmptyDefInstrActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miEmptyDefInstrActionPerformed
    miEmptyDefInstr.setSelected(true);
    Preferences.userNodeForPackage(MRMainFrame.class)
            .remove("default.instruction_set");
    miCurDefInstr.setText("");
    defmemcolors=null;
}//GEN-LAST:event_miEmptyDefInstrActionPerformed

  private void miNewDefMemoryActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miNewDefMemoryActionPerformed
    JFileChooser jf = new JFileChooser();
    if(lastpath!=null)jf.setSelectedFile(new File(lastpath));
    int i=0;
    jf.setDialogTitle(bundle_interfaccia.getString("Scegli_Dump_della_memoria"));
    jf.setDialogType(JFileChooser.OPEN_DIALOG);
    jf.setMultiSelectionEnabled(false);
    if(jf.showOpenDialog(null)==JFileChooser.CANCEL_OPTION)return;

    if(jf.getSelectedFile()!=null){
      lastpath=jf.getSelectedFile().getAbsolutePath();
      Preferences.userNodeForPackage(MRMainFrame.class)
              .put("default.memory_image", lastpath);
      Preferences.userNodeForPackage(MRMainFrame.class).put("default.opendialogs.path", lastpath);
      defmemimage=lastpath;
      miCurDefMemory.setText(lastpath);
      miEmptyDefMemory.setSelected(false);
    }

}//GEN-LAST:event_miNewDefMemoryActionPerformed

  private void miNewDefColorsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miNewDefColorsActionPerformed
    JFileChooser jf = new JFileChooser();
    if(lastpath!=null)jf.setSelectedFile(new File(lastpath));
    int i=0;
    jf.setDialogTitle(bundle_interfaccia.getString("Scegli_Configurazione_della_memoria"));
    jf.setDialogType(JFileChooser.OPEN_DIALOG);
    jf.setMultiSelectionEnabled(false);
    if(jf.showOpenDialog(null)==JFileChooser.CANCEL_OPTION)return;

    if(jf.getSelectedFile()!=null){
      lastpath=jf.getSelectedFile().getAbsolutePath();
      Preferences.userNodeForPackage(MRMainFrame.class)
              .put("default.memory_colors", lastpath);
      Preferences.userNodeForPackage(MRMainFrame.class).put("default.opendialogs.path", lastpath);
      defmemcolors=lastpath;
      miCurDefColors.setText(lastpath);
      miDefColors.setSelected(false);
    }

}//GEN-LAST:event_miNewDefColorsActionPerformed

  private void miNewDefInstrActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miNewDefInstrActionPerformed
    JFileChooser jf = new JFileChooser();
    if(lastpath!=null)jf.setSelectedFile(new File(lastpath));
    int i=0;
    jf.setDialogTitle(bundle_interfaccia.getString("Scegli_Set_di_Istruzioni"));
    jf.setDialogType(JFileChooser.OPEN_DIALOG);
    jf.setMultiSelectionEnabled(false);
    if(jf.showOpenDialog(null)==JFileChooser.CANCEL_OPTION)return;

    if(jf.getSelectedFile()!=null){
      lastpath=jf.getSelectedFile().getAbsolutePath();
      Preferences.userNodeForPackage(MRMainFrame.class)
              .put("default.instruction_set", lastpath);
      Preferences.userNodeForPackage(MRMainFrame.class).put("default.opendialogs.path", lastpath);
      definstructions=lastpath;
      miCurDefInstr.setText(lastpath);
      miEmptyDefInstr.setSelected(false);
    }

}//GEN-LAST:event_miNewDefInstrActionPerformed

  private void miLoadTapeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miLoadTapeActionPerformed
    String[] options = {bundle_interfaccia.getString("Nastro"),bundle_interfaccia.getString("ASCII"),bundle_interfaccia.getString("Binario"),bundle_interfaccia.getString("Interi"),bundle_interfaccia.getString("Annulla")};
    File fi ;
    
    JFileChooser jf = new JFileChooser();
    if(lastpath!=null)jf.setSelectedFile(new File(lastpath));
    jf.setDialogTitle(bundle_interfaccia.getString("Carica_nastro"));
    jf.setDialogType(JFileChooser.OPEN_DIALOG);
    jf.setMultiSelectionEnabled(false);
    if(jf.showOpenDialog(null)==JFileChooser.CANCEL_OPTION)return;

    if((fi=jf.getSelectedFile())==null) return;
    
    int o = 3;
    
    String fine = jf.getSelectedFile().getName().toLowerCase();
    fine = fine.substring(fine.lastIndexOf("."));
    
    if(fine.equals(".bin")) o = 2;
    else if(fine.equals(".tape")) o = 0;
    else if(fine.equals(".ascii")) o = 1;
    else if(fine.equals(".int")) o = 3;
    
    int frmt = JOptionPane.showOptionDialog(this, 
            bundle_interfaccia.getString("Scegli_il_formato:"), bundle_interfaccia.getString("Caricamento_nastro"), 
            JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, 
            null, options, options[o]);
    lastpath=jf.getSelectedFile().getAbsolutePath();
    
    try{
        mtape.load(_mkloader(fi,frmt));
        return;
    }catch(FileNotFoundException ignore){}
    catch(NullPointerException ignore){}
    Preferences.userNodeForPackage(MRMainFrame.class).put("default.opendialogs.path", lastpath);
    
    JOptionPane.showMessageDialog(null, bundle_interfaccia.getString("Errore_nel_caricamento!"), bundle_interfaccia.getString("Errore!"),
                  JOptionPane.ERROR_MESSAGE);
}//GEN-LAST:event_miLoadTapeActionPerformed

  private void miSaveTapeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miSaveTapeActionPerformed
    String[] options = {bundle_interfaccia.getString("Nastro"),bundle_interfaccia.getString("ASCII"),bundle_interfaccia.getString("Binario"),bundle_interfaccia.getString("Interi"),bundle_interfaccia.getString("Annulla")};
    File fi ;
    
    JFileChooser jf = new JFileChooser();
    if(lastpath!=null)jf.setSelectedFile(new File(lastpath));
    jf.setDialogTitle(bundle_interfaccia.getString("Salva_nastro"));
    jf.setDialogType(JFileChooser.SAVE_DIALOG);
    jf.setMultiSelectionEnabled(false);
    if(jf.showSaveDialog(null)==JFileChooser.CANCEL_OPTION)return;
    
    if((fi=jf.getSelectedFile())==null) return;
    
    int o = 3;
    
    String fine = jf.getSelectedFile().getName().toLowerCase();
    fine = fine.substring(fine.lastIndexOf("."));

    if(fine.equals(".bin")) o = 1;
    else if(fine.equals(".tape")) o = 3;
    else if(fine.equals(".ascii")) o = 0;
    else if(fine.equals(".int")) o = 2;
    
    int frmt = JOptionPane.showOptionDialog(this, 
            bundle_interfaccia.getString("Scegli_il_formato:"), bundle_interfaccia.getString("Salvataggio_nastro"), 
            JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, 
            null, options, options[o]);
    lastpath=jf.getSelectedFile().getAbsolutePath();
    Preferences.userNodeForPackage(MRMainFrame.class).put("default.opendialogs.path", lastpath);
    
    try{
        mtape.save(_mkwriter(fi,frmt));
        return;
    }catch(FileNotFoundException ignore){}
    catch(IOException ignore){}
    catch(NullPointerException ignore){}
    JOptionPane.showMessageDialog(null, bundle_interfaccia.getString("Errore_nel_salvataggio!"), bundle_interfaccia.getString("Errore!"),
                  JOptionPane.ERROR_MESSAGE);
}//GEN-LAST:event_miSaveTapeActionPerformed

  private void miEmptyDefTapeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miEmptyDefTapeActionPerformed
    miEmptyDefTape.setSelected(true);
    Preferences.userNodeForPackage(MRMainFrame.class)
            .remove("default.tape");
    Preferences.userNodeForPackage(MRMainFrame.class)
            .remove("default.tape.type");
    miCurDefTape.setText("");
    deftape=null;
    deftapetype=-1;
}//GEN-LAST:event_miEmptyDefTapeActionPerformed

  private void miNewDefTapeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miNewDefTapeActionPerformed
    String[] options = {bundle_interfaccia.getString("ASCII"),bundle_interfaccia.getString("Binario"),bundle_interfaccia.getString("Interi"),bundle_interfaccia.getString("Annulla")};
    JFileChooser jf = new JFileChooser();
    if(lastpath!=null)jf.setSelectedFile(new File(lastpath));
    int i=0;
    jf.setDialogTitle(bundle_interfaccia.getString("Scegli_nastro"));
    jf.setDialogType(JFileChooser.OPEN_DIALOG);
    jf.setMultiSelectionEnabled(false);
    if(jf.showOpenDialog(null)==JFileChooser.CANCEL_OPTION)return;
    
    if(jf.getSelectedFile()==null)return;
    
    int o = 3;
    String fine = jf.getSelectedFile().getName().toLowerCase();
    fine = fine.substring(fine.lastIndexOf("."));
    
    if(fine.equals(".bin")) o = 1;
    else if(fine.equals(".ascii")) o = 0;
    else if(fine.equals(".int")) o = 2;
    
    int frmt = JOptionPane.showOptionDialog(this, 
            bundle_interfaccia.getString("Scegli_il_formato:"), bundle_interfaccia.getString("Scelta_nastro"), 
            JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, 
            null, options, options[o]);
    
    lastpath=jf.getSelectedFile().getAbsolutePath();
    Preferences.userNodeForPackage(MRMainFrame.class)
            .put("default.tape", lastpath);
    Preferences.userNodeForPackage(MRMainFrame.class)
            .putInt("default.tape.type", frmt);

    Preferences.userNodeForPackage(MRMainFrame.class).put("default.opendialogs.path", lastpath);
    deftape=lastpath;
    deftapetype=frmt;
    miCurDefTape.setText(lastpath);
    miEmptyDefMemory.setSelected(false);

}//GEN-LAST:event_miNewDefTapeActionPerformed

  private void miSaveTeletypeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miSaveTeletypeActionPerformed
        String[] options = {bundle_interfaccia.getString("ASCII"),bundle_interfaccia.getString("Binario"),bundle_interfaccia.getString("Interi"),bundle_interfaccia.getString("Testo"),bundle_interfaccia.getString("Annulla")};
    File fi ;
    
    JFileChooser jf = new JFileChooser();
    if(lastpath!=null)jf.setSelectedFile(new File(lastpath));
    jf.setDialogTitle(bundle_interfaccia.getString("Salva_output_telescrivente"));
    jf.setDialogType(JFileChooser.SAVE_DIALOG);
    jf.setMultiSelectionEnabled(false);
    if(jf.showSaveDialog(null)==JFileChooser.CANCEL_OPTION)return;
    
    if((fi=jf.getSelectedFile())==null) return;
    
    int o = 3;
    
    String fine = jf.getSelectedFile().getName().toLowerCase();
    
    int last = fine.lastIndexOf(".");
    if(last>=0)
     fine = fine.substring(last);
    else fine="";
    
    if(fine.equals(".bin")) o = 1;
    else if(fine.equals(".ascii")) o = 0;
    else if(fine.equals(".int")) o = 2;
    else if(fine.equals(".txt")) o = 4;
    
    int frmt = JOptionPane.showOptionDialog(this, 
            bundle_interfaccia.getString("Scegli_il_formato:"), bundle_interfaccia.getString("Salvataggio_output_telescrivente"), 
            JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, 
            null, options, options[o]);
    lastpath=jf.getSelectedFile().getAbsolutePath();

    Preferences.userNodeForPackage(MRMainFrame.class).put("default.opendialogs.path", lastpath);
    
    try{
        if(frmt==4)
          mtty.saveText(fi);
        else
          mtty.save(_mkwriter(fi, frmt));
        return;
    }catch(FileNotFoundException ignore){}
    catch(IOException ignore){}
    catch(NullPointerException ignore){}
    JOptionPane.showMessageDialog(null, bundle_interfaccia.getString("Errore_nel_salvataggio!"), bundle_interfaccia.getString("Errore!"),
                  JOptionPane.ERROR_MESSAGE);
}//GEN-LAST:event_miSaveTeletypeActionPerformed

  private void miSystemDecorationsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miSystemDecorationsActionPerformed
    Preferences.userNodeForPackage(MRMainFrame.class)
        .put("default.uselafdecorations", ""+!miSystemDecorations.isSelected());
    JFrame.setDefaultLookAndFeelDecorated(!miSystemDecorations.isSelected());
}//GEN-LAST:event_miSystemDecorationsActionPerformed

  private void jMenuitem19ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuitem19ActionPerformed
      try{
          _setrefresh((JRadioButtonMenuItem)(evt.getSource()));
      }catch(ClassCastException ignore){}
}//GEN-LAST:event_jMenuitem19ActionPerformed

  private void miItalianActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miItalianActionPerformed
    Preferences.userNodeForPackage(MRMainFrame.class).put("default.language", "it");
  }//GEN-LAST:event_miItalianActionPerformed

  private void miDefaultLanguageActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miDefaultLanguageActionPerformed
    Preferences.userNodeForPackage(MRMainFrame.class).remove("default.language");
  }//GEN-LAST:event_miDefaultLanguageActionPerformed

  private void miEnglishActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miEnglishActionPerformed
    Preferences.userNodeForPackage(MRMainFrame.class).put("default.language", "en");
  }//GEN-LAST:event_miEnglishActionPerformed

  private void miEsperantoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miEsperantoActionPerformed
    Preferences.userNodeForPackage(MRMainFrame.class).put("default.language", "eo");
  }//GEN-LAST:event_miEsperantoActionPerformed

  private void miSoundFXActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miSoundFXActionPerformed
    classictty.setSoundEnabled(miSoundFX.isSelected());
    Preferences.userNodeForPackage(MRMainFrame.class)
            .putBoolean("sound.enabled", miSoundFX.isSelected());
}//GEN-LAST:event_miSoundFXActionPerformed

  private void mnuResetToDefaultImageActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnuResetToDefaultImageActionPerformed
      load_def_mem_image();
      ubp.updateMEM();
}//GEN-LAST:event_mnuResetToDefaultImageActionPerformed

  private void mnuResetToLastImageActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnuResetToLastImageActionPerformed
    if(lastloaded==null)return;
    try{
        mrm.loadMemDump(new File(lastloaded),last_base);
        ubp.updateMEM();
    }
    catch(FileNotFoundException ignore){}
    catch(IOException ignore){}
}//GEN-LAST:event_mnuResetToLastImageActionPerformed
    
  private void _setrefresh(JRadioButtonMenuItem who){
      int ref=1000;
    
    if(who==miRefresh500ms)ref=500;
    else if(who==miRefresh200ms)ref=200;
    else if(who==miRefresh100ms)ref=100;
    else if(who==miRefresh50ms)ref=50;
    else if(who==miRefresh20ms)ref=20;
    
    ubp.setRefresh(ref);    
  }


 public static ImageIcon resizeIcon(ImageIcon w,int nx, int ny){
    return new ImageIcon(
            w.getImage().getScaledInstance(
            nx,ny,java.awt.Image.SCALE_SMOOTH));
 }


 public static void initSound(String nome, URL urlo){
    Clip cc;
    AudioInputStream ais;
    if(nosound)return;
    try{
        ais = AudioSystem.getAudioInputStream(urlo);
        cc = AudioSystem.getClip();
        cc.open(ais);
        suoni.put(nome, cc);
    }
    catch(LineUnavailableException e){nosound=true;e.printStackTrace();}
    catch(Exception e){e.printStackTrace();}
 }

 public static void playSound(String nome){
    Clip cl;
    cl = suoni.get(nome);
    if(cl==null){
        System.err.println("Sound \""+nome+"\" not found.");
        return;
    }
    cl.setFramePosition(0);
    cl.start();
 }

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        boolean nojdk=false;
        String wallpaper=null;
        
        // this works for java 5, but not java 6
        // In java 6 should not be needed at all.
        System.setProperty("swing.aatext", "true");
        
//        JFrame.setDefaultLookAndFeelDecorated(
//            Boolean.parseBoolean(
//                Preferences.userNodeForPackage(MRMainFrame.class)
//                    .get("default.uselafdecorations", null))
//            );
        
        for(String s:args){
            if(s.equals("--no-jdk")||s.equals("--nojdk"))
                nojdk=true;
            if(s.startsWith("--with-background=")||
                    s.startsWith("--with-wallpaper=")||
                    s.startsWith("--wallpaper="))
                wallpaper=s.substring(s.indexOf("=")+1);
                
        }
        MRUtils.hasJDK=!nojdk;
        if(wallpaper!=null)
            System.setProperty("macchinaridotta.wallpaper", wallpaper);
        
        String deflang = Preferences.userNodeForPackage(MRMainFrame.class)
                .get("default.language",null);
        
        if(deflang!=null){
            Locale.setDefault(new Locale(deflang));
            bundle_interfaccia = 
                ResourceBundle.getBundle("interfaccia/Bundle_interfaccia",
                    new Locale(deflang));
        }
        

        SwingUtilities.invokeLater(new Runnable() {  
            public void run() {
                new MRMainFrame().setVisible(true);
            }
        });
        

        initSound("teletype2",
                MRMainFrame.class.getResource("/interfaccia/teletype2.wav"));
        initSound("teletype1",
                MRMainFrame.class.getResource("/interfaccia/teletype3.wav"));
        initSound("teletype0", //longer
                MRMainFrame.class.getResource("/interfaccia/teletype4.wav"));
        
        Runtime.getRuntime().addShutdownHook(new Thread(){
            public void run(){
                try {
                    Preferences.userNodeForPackage(MRMainFrame.class).flush();
                } catch (BackingStoreException ignore) {}
            }
        });
        
    }

  // Variables declaration - do not modify//GEN-BEGIN:variables
  private javax.swing.JMenu jMenu1;
  private javax.swing.JMenu jMenu10;
  private javax.swing.JMenu jMenu11;
  private javax.swing.JMenu jMenu13;
  private javax.swing.JMenu jMenu2;
  private javax.swing.JMenu jMenu3;
  private javax.swing.JMenu jMenu4;
  private javax.swing.JMenu jMenu5;
  private javax.swing.JMenu jMenu6;
  private javax.swing.JMenu jMenu7;
  private javax.swing.JMenu jMenu8;
  private javax.swing.JMenu jMenu9;
  private javax.swing.JMenuBar jMenuBar1;
  private javax.swing.JMenuItem jMenuItem12;
  private javax.swing.JMenuItem jMenuItem14;
  private javax.swing.JMenuItem jMenuItem17;
  private javax.swing.JMenuItem jMenuItem26;
  private javax.swing.JSeparator jSeparator1;
  private javax.swing.JSeparator jSeparator10;
  private javax.swing.JSeparator jSeparator11;
  private javax.swing.JSeparator jSeparator12;
  private javax.swing.JSeparator jSeparator13;
  private javax.swing.JSeparator jSeparator2;
  private javax.swing.JSeparator jSeparator3;
  private javax.swing.JSeparator jSeparator4;
  private javax.swing.JSeparator jSeparator5;
  private javax.swing.JSeparator jSeparator6;
  private javax.swing.JSeparator jSeparator7;
  private javax.swing.JSeparator jSeparator8;
  private javax.swing.JSeparator jSeparator9;
  private javax.swing.JTabbedPane jTabbedPane1;
  private javax.swing.JMenu menuConfigs;
  private javax.swing.JMenu menuLAF;
  private javax.swing.JMenuItem miCurDefColors;
  private javax.swing.JMenuItem miCurDefInstr;
  private javax.swing.JMenuItem miCurDefMemory;
  private javax.swing.JMenuItem miCurDefTape;
  private javax.swing.JCheckBoxMenuItem miDefColors;
  private javax.swing.JMenuItem miDefaultLanguage;
  private javax.swing.JMenuItem miDumpMemory;
  private javax.swing.JCheckBoxMenuItem miEmptyDefInstr;
  private javax.swing.JCheckBoxMenuItem miEmptyDefMemory;
  private javax.swing.JCheckBoxMenuItem miEmptyDefTape;
  private javax.swing.JMenuItem miEnglish;
  private javax.swing.JMenuItem miEsperanto;
  private javax.swing.JMenuItem miInformations;
  private javax.swing.JMenuItem miItalian;
  private javax.swing.JMenuItem miLoadColors;
  private javax.swing.JMenuItem miLoadInstr;
  private javax.swing.JMenuItem miLoadMemory;
  private javax.swing.JMenuItem miLoadTape;
  private javax.swing.JMenuItem miNewDefColors;
  private javax.swing.JMenuItem miNewDefInstr;
  private javax.swing.JMenuItem miNewDefMemory;
  private javax.swing.JMenuItem miNewDefTape;
  private javax.swing.JMenuItem miQuit;
  private javax.swing.JRadioButtonMenuItem miRefresh100ms;
  private javax.swing.JRadioButtonMenuItem miRefresh1s;
  private javax.swing.JRadioButtonMenuItem miRefresh200ms;
  private javax.swing.JRadioButtonMenuItem miRefresh20ms;
  private javax.swing.JRadioButtonMenuItem miRefresh500ms;
  private javax.swing.JRadioButtonMenuItem miRefresh50ms;
  private javax.swing.JMenuItem miResetClock;
  private javax.swing.JMenuItem miSaveColors;
  private javax.swing.JMenuItem miSaveInstr;
  private javax.swing.JMenuItem miSaveTape;
  private javax.swing.JMenuItem miSaveTeletype;
  private javax.swing.JCheckBoxMenuItem miSoundFX;
  private javax.swing.JRadioButtonMenuItem miSpeedBest;
  private javax.swing.JRadioButtonMenuItem miSpeedHistorical;
  private javax.swing.JRadioButtonMenuItem miSpeedSlow;
  private javax.swing.JRadioButtonMenuItem miSpeedVerySlow;
  private javax.swing.JCheckBoxMenuItem miSystemDecorations;
  private javax.swing.JMenuItem mnuResetToDefaultImage;
  private javax.swing.JMenuItem mnuResetToLastImage;
  private javax.swing.ButtonGroup refreshGroup;
  private javax.swing.ButtonGroup speedGroup;
  // End of variables declaration//GEN-END:variables
    
}
